package net.coding.api.test.helper.impl.enterprise;

import io.restassured.response.Response;
import net.coding.api.test.common.ProjectInfo;
import net.coding.api.test.helper.BaseProjectHelper;

import static net.coding.api.test.ApiMethod.POST;
import static net.coding.api.test.TestClient.client;
import static net.coding.api.test.TestHelper.userHelper;

/**
 * Created with IntelliJ IDEA.
 * User: chenfeilong
 * Date: 2018/1/17
 * Time: 15:57
 * Description:
 */
public class EnterpriseProjectHelper implements BaseProjectHelper {

    @Override
    public Response createProject(int userIndex, int type, String name, String description, boolean gitEnabled, boolean gitReadmeEnabled, String gitIgnore, String gitLicense, String vcsType) {
       return client().login().params(getCreateProjectParams(type, name, description, gitEnabled
                , gitReadmeEnabled, gitIgnore, gitLicense, vcsType)).request(POST, String.format("/team/%s/project", userHelper.getGlobalKey())).response();
    }

    @Override
    public Response deleteProject(int userIndex, ProjectInfo projectInfo) {
        // 2018/1/18 使用两步验证强制删除
       return client().login(userIndex).request(POST, String.format("/team/%s/project/%s/delete?two_factor_code=%s"
                , userHelper.getGlobalKey(), projectInfo.getId(), userHelper.getPassword(userIndex,true)))
                .response();
    }

    @Override
    public Integer getProjectCreatorRole() {
        //企业版创建者权限为管理员（90）
        return 90;
    }

    @Override
    public String getProjectPath(String projectName) {
        return String.format("/p/%s",projectName);
    }

    @Override
    public String getBackendProjectPath(String projectName)
    {
        return String.format("/team/%s/project/%s", userHelper.getGlobalKey(), projectName);
    }
}
